<?php
namespace Home\Controller;
use Think\Controller;
class FeedbackController extends Controller {
    public function Feedback(){
        if(IS_POST){
            $post = I('post.');
            if(empty($post['title'])){
                $this->error('标题不能为空');
            }
            if(empty($post['name'])){
                $this->error('名字不能为空');
            }
            if(empty($post['phone'])){
                $this->error('电话不能为空');
            }
            if(empty($post['email'])){
                $this->error('邮箱不能为空');
            }
            if(empty($post['text'])){
                $this->error('留言内容不能为空');
            }
            $model = M('feedback');
            $post['time'] = time();
            // var_dump($post);die;
            $result = $model -> add($post);
            if($result){
                $this->success('发表成功', U('Feedback/feedback'), 3);
            }else{
                $this->error('发表失败');
            }
            // var_dump($post);die;
        }else{
            $model = M('feedback');
            $data = $model -> order('time desc') -> limit(0,5) -> select();
            // var_dump($data);die;
            $this -> assign('data',$data);
            $this -> display();
        }      
    }
}